﻿using System;

namespace DoDoveFramework
{
    public abstract class Singleton<T> where T : class, new()
    {
        private static readonly Lazy<T> _lazyInstance = new Lazy<T>(() => new T());
        
        public static T Instance => _lazyInstance.Value;
        
        protected Singleton()
        {
            // 防止通过反射创建多个实例
            if (_lazyInstance.IsValueCreated)
            {
                throw new InvalidOperationException("单例类不允许创建多个实例");
            }

            Initialize();
        }

        protected abstract void Initialize();

    }
}